import React, { Component } from 'react';
import { Table } from 'antd';

import SuperForm from '../SuperForm'
class SuperPut extends Component {
    static defaultProps = {
        filter: [],
        loading: false,
        dataSource: [],
        operate: [],
        tableColumns: [],
        onSubmit: () => { }
    }
    //操作函数
    get render_operate() {
        const operates = []
        this.props.operate.forEach((item, index) => {
            if (!item.hide) {
                operates.push(
                    React.cloneElement(item.label, {
                        onClick: item.onClick,
                        key: index
                    })
                )
            }
        })
        return operates
    }
    handlerSubmit = (values) => {
        this.props.fetchFun(values)
    }
    render() {
        const { filter, loading, dataSource, columns, key } = this.props
        return (
            <div>
                <div>
                    <SuperForm items={filter}
                        layout='inline'
                        size='middle'
                        onSubmit={this.handlerSubmit}
                        submitText='查询'
                    />
                    <div className='operate-bar'>
                        {this.render_operate}
                    </div>
                    <Table
                        rowKey={key}
                        loading={loading}
                        columns={columns}
                        dataSource={dataSource} />
                </div>
            </div>
        );
    }
}

export default SuperPut;